import 'package:flutter/material.dart';
import 'package:metaera_flutter/utils/Font.dart';
import 'package:metaera_flutter/utils/Color.dart';
import 'package:cached_network_image/cached_network_image.dart'; // 添加导入

class CategoryItem extends StatelessWidget {
  final int index;
  final int currentIndex;
  final String title;
  final PageController pageController;

  const CategoryItem({
    super.key,
    required this.index,
    required this.title,
    required this.currentIndex,
    required this.pageController,
  });

  @override
  Widget build(BuildContext context) {
    return Container(
      margin: EdgeInsets.symmetric(horizontal: 16, vertical: 12),
      child: GestureDetector(
        behavior: HitTestBehavior.translucent,
        onTap: () {
          pageController.animateToPage(
            index,
            duration: Duration(milliseconds: 300),
            curve: Curves.easeInOut,
          );
        },
        child: Column(
          children: [
            Text(
              title,
              style: TextStyle(
                color: currentIndex == index
                    ? AppColors.color333
                    : AppColors.color9C9C9C,
                fontWeight: currentIndex == index
                    ? AppFonts.fontWeight600
                    : AppFonts.fontWeight400,
                fontSize: 16,
              ),
            ),
            if (currentIndex == index)
              Container(
                margin: EdgeInsets.only(top: 4),
                child: Image.asset(
                  'assets/images/base/tab_arrow.png',
                  width: 9,
                  height: 6,
                  fit: BoxFit.contain,
                ),
              ),
            if (currentIndex != index)
              Container(
                margin: EdgeInsets.only(top: 4),
                height: 6,
                color: AppColors.color333,
              ),
          ],
        ),
      ),
    );
  }
}
